package cn.wen233.srpc.core.execute;

import cn.wen233.srpc.basic.execute.Executor;
import cn.wen233.srpc.basic.filter.ClientFilter;
import cn.wen233.srpc.basic.model.Request;
import cn.wen233.srpc.basic.model.Response;
import cn.wen233.srpc.core.service.spi.SPIContext;
import cn.wen233.srpc.core.utils.ServiceLoaderUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 客户端 Executor
 *
 * @author wenei
 * @date 2021-10-28 16:18
 */
public interface ClientExecutor extends Executor {

    /**
     * 子类实现具体实现
     * @param request 请求信息
     * @return 响应数据
     */
    Response doExecute(Request request);

    @Override
    default Response execute(Request request) {
        for (ClientFilter filter : SPIContext.loadService(ClientFilter.class)) {
            if (!filter.filter(request)) {
                return Response.REFUSE;
            }
        }
        return doExecute(request);
    }
}
